import { createApp } from 'vue'
import { createPinia } from 'pinia'
import './styel.css'
import Vant from 'vant'
import 'vant/lib/index.css'
import App from './App.vue'
import router from './router'
import Axios from 'axios'
import VConsole from 'vconsole'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

// import './assets/main.css'
// const vConsole = new VConsole({ theme: 'dark' });
// vConsole.destroy();
const app = createApp(App)

app.use(createPinia())
app.use(createPinia().use(piniaPluginPersistedstate))
app.use(router)
app.use(Vant)
app.config.globalProperties.$http = Axios

app.mount('#app')

router.beforeEach((to, from, next) => {

    console.log('进入导航', localStorage.getItem('token'))
    console.log('router', to)
    console.log('111',from.path)

    if (localStorage.getItem('token')) {
        console.log('yes token')
        if(to.path === "/signIn"){
            next()
        }else{
            
            if (to.path === "/login") {
                next({ path: '/indexpage' })
            } else {
                next()
            }
        }
        
    } else {
        if (to.query.code){
            localStorage.setItem('code', `${to.query.code}`)
            localStorage.setItem('state', `${to.query.state}`)
            next()
        }else{
            if(to.path == '/signIn'){
                // let e = 'https://sdk.nextjoy.com/api/wx/GetOpenId?gid=34&type=sign'
                // let e = 'https://mtshop.nextjoy.com.cn/signIn?gid=34&type=sign'
                // let e = 'http://172.20.10.2:5176/signIn?gid=34&type=sign'
                // window.location.href = e
                next()
            }else{
                let e = 'https://sdk.nextjoy.com/api/wx/GetOpenId?gid=34'
                window.location.href = e
            }
            next()
        }
        
    }
})